<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜房订单--订单详情表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row" id="printArea">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <!--菜房1-->
                        <!--<input type="hidden" name="cforderFor" value="1"/>-->
                        <input type="hidden" name="orderId" th:value="${orderId}"/>
                        <li>
                            订单类型：<select name="cforderType" th:with="type=${@dict.getType('cforderType')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            作物名称：<input type="text" name="cropNameCn"/>
                        </li>

                        <li>
                            作物品种：<input type="text" name="cropVarietiesCn"/>
                        </li>

                        <li class="select-time">
                            <label>需求时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>

                        <li>
                            状态：<select name="cforderStatus" th:with="type=${@dict.getType('cforderStatus')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <h3 align="center"> <span th:text="订单表" id="ordercode" hidden="hidden"></span> </h3>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
            <h3> <span class="fl-l" id="autograph" hidden="hidden"></span> </h3>
        </div>

        <div class="btn-group-sm" id="toolbar1" role="group">

            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning" id="print-btn" orderType = "3">
                <i class="fa fa-download"></i> 打印
            </a>
            <!--            <div></div>-->
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncOrderCf:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncOrderCf:remove')}]];
    var prefix = ctx + "system/ncOrderCf";
    var datas = [[${@dict.getType('cforderType')}]];
    var cforderStatus = [[${@dict.getType('cforderStatus')}]];
    var normal_unit = [[${@dict.getType('normal_unit')}]];
    $(function () {
        var options = {
            url: prefix + "/list?orderId="+[[${orderId}]],
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export?orderId="+[[${orderId}]],
            modalName: "菜房订单",
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            toolbar: 'toolbar1',
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'cforderCode',
                    title: '订单编号',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: true
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'requestTime',
                    title: '需求日期',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }
                },
                {
                    field: 'cforderId',
                    title: '菜房订单键',
                    visible: false
                },
                {
                    field: 'cforderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },

                {
                    field: 'requestAmount',
                    title: '需求数量',
                    sortable: true
                },
                {
                    field: 'unit',
                    title: '单位',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(normal_unit, value);
                    }
                },

                {
                    field: 'cforderStatus',
                    title: '状态',
                    sortable: false,
                    formatter: function (value, row, index) {
                        /*蔬菜类状态：1、待分配，2、待检测，3、待入库，4、待出库，5、已完成
                        牛奶鸡蛋：6、牛舍待确认，7、鸡舍待确认，8、牛舍已确认，9、鸡舍已确认*/
                        return $.table.selectDictLabel(cforderStatus, value);
                    }
                },
                {
                    field: 'distribution',
                    title: '分配情况',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "检测"
                        }
                        if (2 == value) {
                            return "仓储"
                        }
                        return "--";
                    }
                },
                {
                    field: 'hasPlan',
                    title: '匹配计划',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if ('1' == value) {
                            return row.planCode
                        }
                        if ('2' == value) {
                            return "未匹配"
                        }
                        return "--";
                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editOrderPlan(\'' + row.cforderId + '\')"><i class="fa fa-warning"></i>匹配计划</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cforderId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.cforderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable";
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {

            $.modal.confirm("确认生成订单记录单吗？", function () {
                var ids = [];
                $(data).each(function (i, e) {
                    ids.push(e.cforderId);
                });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {
                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        $.table.refresh()
                    }, function (e) {
                        layer.msg("确认失败!");
                        $.table.refresh()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }

    function editOrderPlan(cforderId) {
        var url = ctx + 'system/ncOrderCf/editOrderPlan/' + cforderId
        $.modal.open("匹配计划", url);
    }

    setTitle("订单预览",true)
</script>
</body>
</html>